﻿using com.bodurov.SilverlightControls.XmlCodeEditor.Enums;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using E = com.bodurov.SilverlightControls.XmlCodeEditor.Enums.XmlElement;
using A = com.bodurov.SilverlightControls.XmlCodeEditor.Enums.XmlArea;

namespace com.bodurov.SilverlightControls.XmlCodeEditor.Tests
{
    [TestClass]//[Ignore]
    public class IterativeTokenizerCanParseSimpleTags : BaseTokenFixture
    {

        [TestMethod]//[Ignore]
        public void CanAddSimpleCompleteTag()
        {
            const string str = "<br />";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("br", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("/>", E.OpeningTagClosingBracket)));
        }
        [TestMethod]//[Ignore]
        public void CanAddSimpleOpenTag()
        {
            const string str = "<table>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideTag,
                    Expect("<", E.OpeningTagBeginBracket),
                    Expect("table", E.OpeningTagName),
                    Expect(">", E.OpeningTagEndBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleClosingTag()
        {
            const string str = "</h3>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideTag,
                    Expect("</", E.ClosingTagBeginBracket),
                    Expect("h3", E.ClosingTagName),
                    Expect(">", E.ClosingTagEndBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleClientSideComment()
        {
            const string str = "<!--\n\t some comment content goes here \n-->";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideClientSideComment,
                    Expect("<!--", E.OpeningClientSideCommentBracket),
                    Expect_NewLine,
                    Expect("\t some comment content goes here ", E.InsideClientSideComment),
                    Expect_NewLine,
                    Expect("-->", E.ClosingClientSideCommentBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleServerPrintScript()
        {

            const string str = @"<%= Eval(""User_Name"") %>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideServerScriptPrintCode,
                    Expect("<%", E.OpeningServerScriptBracket),
                    Expect("=", E.ServerBlockSpecialChar),
                    Expect(@" Eval(""User_Name"") ", E.InsideServerScript),
                    Expect("%>", E.ClosingServerScriptBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleServerBindStatement()
        {
            const string str = @"<%#SomeServerSideMethod %>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideServerBindStatement,
                    Expect("<%", E.OpeningServerScriptBracket),
                    Expect("#", E.ServerBlockSpecialChar),
                    Expect(@"SomeServerSideMethod ", E.InsideServerScript),
                    Expect("%>", E.ClosingServerScriptBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleServerScript()
        {
            const string str = "<%\n\tHelper.DoSomething();\n%>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideServerScriptCode,
                    Expect("<%", E.OpeningServerScriptBracket),
                    Expect_NewLine,
                    Expect("\tHelper.DoSomething();", E.InsideServerScript),
                    Expect_NewLine,
                    Expect("%>", E.ClosingServerScriptBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleServerDeclaration()
        {
            const string str = @"<%@ Page %>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);


            AssertTokens(tokens,
                Within(A.InsideServerDeclaration,
                    Expect("<%", E.OpeningServerScriptBracket),
                    Expect("@", E.ServerBlockSpecialChar),
                    Expect(" ", E.WhiteSpace),
                    Expect("Page", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("%>", E.ClosingServerScriptBracket)));
        }

        [TestMethod]//[Ignore]
        public void CanAddSimpleProcessingInstruction()
        {
            const string str = @"<?xml ?>";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.InsideProcessingInstruction,
                    Expect("<?", E.OpeningProcessingInstructionBracket),
                    Expect("xml", E.OpeningTagName),
                    Expect(" ", E.WhiteSpace),
                    Expect("?>", E.ClosingProcessingInstructionBracket)));
        }
    }
}
